package j04pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class J1 {
    public static void main(String[] args) throws InterruptedException {
//        ExecutorService es = Executors.newFixedThreadPool(3);
//        ExecutorService es = Executors.newCachedThreadPool();
        ExecutorService es = Executors.newSingleThreadExecutor();
        es.submit(()->{
            for (int i = 0; i < 100; i++) {
                System.out.println(Thread.currentThread().getName()+"-"+i);
            }
        });
        es.submit(()->{
            for (int i = 0; i < 100; i++) {
                System.out.println(Thread.currentThread().getName()+"-"+i);
            }
        });
        es.submit(()->{
            for (int i = 0; i < 100; i++) {
                System.out.println(Thread.currentThread().getName()+"-"+i);
            }
        });
        es.submit(()->{
            for (int i = 0; i < 100; i++) {
                System.out.println(Thread.currentThread().getName()+"-"+i);
            }
        });
        es.submit(()->{
            for (int i = 0; i < 100; i++) {
                System.out.println(Thread.currentThread().getName()+"-"+i);
            }
        });
        es.submit(()->{
            for (int i = 0; i < 100; i++) {
                System.out.println(Thread.currentThread().getName()+"-"+i);
            }
        });

        Thread.sleep(1000);
        System.out.println("====");
        es.submit(()->{
            for (int i = 0; i < 100; i++) {
                System.out.println(Thread.currentThread().getName()+"-"+i);
            }
        });
        //停止 - 等待子线程结束
//        es.shutdown();
        //立即停止
        es.shutdownNow();

    }
}
